package com.bytedance.improvingroad.activity

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.bytedance.improvingroad.utils.inflateBindingWithGeneric

/**
 * Created by chenxiong
 * date 12/2/21
 */
abstract class BaseBindingActivity<VIEW: ViewBinding>: AppCompatActivity() {
    lateinit var binding: VIEW
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = inflateBindingWithGeneric(layoutInflater)
        setContentView(binding.root)
        initData()
        initListener()
    }

    abstract fun initData()

    abstract fun initListener()

    //跳转并可设置传参
    inline fun <reified T: BaseBindingActivity<ViewBinding>> startActivityAndFinish(parseParamsCall: Intent.()->Unit = {}) {
        Intent(this,T::class.java).let { intent ->
            intent.parseParamsCall()
            startActivity(intent)
        }
        finish()
    }
}